<?php
namespace Crm\Table;

use Zend\Db\Sql\Select;
use Zend\Db\Sql\Where;
use Zend\Db\Sql\Expression;
use Zend\Db\Adapter\Adapter;
class PowerManageTable extends AbstractTable
{
    protected $table = 'hycrm_power_manage';
    protected $id = 'power_id';
    
    
    public function findAll()
    {
        $select = new Select($this->getTable());
        $select->order('menu_code','power_id');
        
        $rowset = $this->selectWith($select);
        $list = $rowset->toArray();
        
        return $list;
        
        
    }
    public function getGroupPower($group_id){
    
        if(empty($group_id)){
            throw new \Exception("id field is invalid!");
        }
        $sql="
            SELECT 
                pm.*, pg.id AS id, pg.user_group_id AS user_group_id
            FROM 
                hycrm_power_manage AS pm
            LEFT JOIN hycrm_power_group AS pg ON pm.power_id = pg.power_id 
                  AND pg.user_group_id=".$group_id ."
            ORDER BY menu_code,power_id";
        $statement=$this->getAdapter()->query($sql,Adapter::QUERY_MODE_EXECUTE);
        
        $row=$statement->toArray();
        return $row;

    }
}